package leetcode;

import java.util.LinkedList;
import java.util.Objects;
import java.util.Queue;
import java.util.Stack;

public class MaxQueue {
    Queue<Integer> queueA;
    Queue<Integer> queueB;

    public MaxQueue() {
        this.queueA = new LinkedList<>();
        this.queueB = new LinkedList<>();
    }

    public int max_value() {
        if (this.queueA.isEmpty() || this.queueB.isEmpty()) {
            return -1;
        }
        return this.queueB.peek();
    }

    public void push_back(int value) {
         if (queueB.isEmpty()) {
            queueB.add(value);
        }
        this.queueA.add(value);
    }

    public int pop_front() {
        if (this.queueA.isEmpty()) {
            return -1;
        }
        if (Objects.equals(this.queueA.peek(), this.queueB.peek())) {
            this.queueB.remove();
        }
        return this.queueA.remove();
    }

    public static void main(String[] args) {
        MaxQueue maxQueue = new MaxQueue();
        maxQueue.push_back(1);
        maxQueue.push_back(2);
        System.out.println(maxQueue.max_value());
        System.out.println(maxQueue.pop_front());
        System.out.println(maxQueue.max_value());
    }
}